// returns a list of extension for the given test class List<PageExtension> getPageExtensions(TestClass testClass);
Page extensions mechanism provides a way to easily install your JavaScript code into the page. Page extensions are used mainly in cooperation with JavaScript Interface, but they can be used independently too.
Extensions has to implement PageExtension interface to define:
name,
JavaScript code to be executed when the extension is installed,
JavaScript code returning true if the extension is already installed, false otherwise,
dependencies.
To provide your own extensions you can use PageExtensionProvider service containg the following method:
// returns a list of extension for the given test class List<PageExtension> getPageExtensions(TestClass testClass);
The second way to provide your own extension is to use PageExtensionRegistry:
PageExtension pageExtension = new MyCoolPageExtension(...); GraphenePageExtensionsContext.getRegistryProxy().register(pageExtension);
The registry can be also used to check whether the given extension is available:
// returns page extension with the given name, or null if there is no extension with the given name GraphenePageExtensionsContext.getRegistryProxy().getExtension("my cool extension");
Each extensions is defined with its name. When you want to install the extension just ask for its installator and install it. All defined dependencies will be installed too. When the extension is detected as already installed, the installation is skipped (including installation of all dependencies).
GraphenePageExtensionsContext.getInstallatorProviderProxy().installator("extension name").install();
The installator is available only for extensions already registered via SPI or registry.
When a page is reloaded, all injected JavaScript code is lost, so the extension has to be installed again.